<?php
defined('IN_IA') or exit('Access Denied');
include MODULE_ROOT . '/tbsdk/TopSdk.php';
global $_W, $_GPC;
if ($_W['ispost']) {
	$uniacid = $_W['uniacid'];
	$setting = $this->baseset($uniacid);
	$id = $_GPC['id'];
	$show = pdo_fetch("SELECT id,itemfee,itemfee2,itemyhj_tkl,itemyhj_url,itempic,d_title,title FROM " . tablename($this->tableitemdtk) . " WHERE uniacid = '{$_W['uniacid']}' AND id = '{$id}' AND status=1");
	if ($show) {
		if (empty($show['itemyhj_tkl']) || $show['itemyhj_tkl'] == 'error') {
			$newurl = $show['itemyhj_url'];
			$logo = $show['itempic'];
			if ($show['d_title']) {
				$text = $show['d_title'] . "【券后价￥" . $show['itemfee2'] . "】";
			} else {
				$text = $show['title'] . "【券后价￥" . $show['itemfee2'] . "】";
			}
			if (!empty($setting['diytkl'])) {
				$text = "【粉丝专享券后价￥" . $show['itemfee2'] . "】" . $setting['diytkl'];
			}
			$newtkl = $this->c_tkl_pro($newurl, $logo, $text);
			$data = array();
			$data['itemyhj_tkl'] = $newtkl;
			pdo_update($this->tableitemdtk, $data, array('id' => $show['id']));
			exit(json_encode(array('status' => 1, 'tkl' => $newtkl)));
		} else {
			exit(json_encode(array('status' => 0, 'tkl' => $show['itemyhj_tkl'])));
		}
	}
}